const state = {
  oaProcessTemplate: {
    templateName: '',
    processTypeId: '',
    iconUrl: '',
    description: '',
    formRule: '',
    formOption: '',
    processDefinitionPath: ''
  }
}

const mutations = {
  // 修改审批设置相关数据
  UPDATE_APPROVAL_SET: (state, approvalSet) => {
    state.oaProcessTemplate.templateName = approvalSet.templateName
    state.oaProcessTemplate.processTypeId = approvalSet.processTypeId
    state.oaProcessTemplate.iconUrl = approvalSet.iconUrl
    state.oaProcessTemplate.description = approvalSet.description
  },
  // 修改表单设计相关数据
  UPDATE_FROM_DESIGN: (state, fromDesign) => {
    state.oaProcessTemplate.formRule = fromDesign.formRule
    state.oaProcessTemplate.formOption = fromDesign.formOption
  },
  // 修改流程设计相关数据
  UPDATE_PROCESS_DESIGN: (state, processDesign) => {
    state.oaProcessTemplate.processDefinitionPath = processDesign.processDefinitionPath
  },
  // 新增：重置oaProcessTemplate到初始状态
  RESET_OA_PROCESS_TEMPLATE: state => {
    state.oaProcessTemplate = {
      templateName: '',
      processTypeId: '',
      iconUrl: '',
      description: '',
      formRule: '',
      formOption: '',
      processDefinitionPath: ''
    }
  }
}

// 异步方法
const actions = {
  // 设置审批设置相关数据
  setApprovalSet({ commit }, approvalSet) {
    commit('UPDATE_APPROVAL_SET', approvalSet)
  },
  // 设置表单设计相关数据
  setFromDesign({ commit }, fromDesign) {
    commit('UPDATE_FROM_DESIGN', fromDesign)
  },
  // 设置流程设计相关数据
  setProcessDesign({ commit }, processDesign) {
    commit('UPDATE_PROCESS_DESIGN', processDesign)
  },
  // 新增：重置oaProcessTemplate
  resetOaProcessTemplate({ commit }) {
    commit('RESET_OA_PROCESS_TEMPLATE')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
